package com.coscon.service.patternCommon.impl.systemos;

import com.coscon.model.IrcaCmd;
import com.coscon.service.patternCommon.ICommand;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.Session;
import java.awt.*;
import java.awt.event.InputEvent;
import java.io.IOException;

/**
 * 系统控制：睡眠
 */
@Slf4j
public class SystemOsSleepCmdImpl implements ICommand {

    private Robot rb;

    public SystemOsSleepCmdImpl(Robot rb){
        this.rb = rb;
    }


    @Override
    public Boolean executeByMac(IrcaCmd cmd, Session session) {
        execSystemSleepByMac();
        return true;
    }

    @Override
    public Boolean executeByWin(IrcaCmd cmd, Session session) {
        this.execSystemSleepByWin();
        return true;
    }

    @Override
    public Boolean executeByLinux(IrcaCmd cmd, Session session) {
        return true;
    }


    public void execSystemSleepByMac() {
        rb.mouseMove(100, 0); //鼠标指针移到最顶部停留
        rb.delay(1000);
        rb.mouseMove(28, 15); //鼠标指针移到左上角的苹果图标
        rb.delay(100);
        //执行单机
        rb.mousePress(InputEvent.BUTTON1_MASK);
        rb.mouseRelease(InputEvent.BUTTON1_MASK);
        rb.delay(100);

        rb.mouseMove(28, 200); //鼠标指针移到睡眠菜单的坐标
        rb.delay(100);
        //执行单机
        rb.mousePress(InputEvent.BUTTON1_MASK);
        rb.mouseRelease(InputEvent.BUTTON1_MASK);
        rb.delay(100);
    }



    public void execSystemSleepByWin() {
        try {
            Runtime.getRuntime().exec("cmd /c shutdown /h -t 0");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
        }
    }
}
